package  com.pcbly.web.business.crm;

/**
* @author carl.song
* Copyright (c) 2010 Lightsoft, International.
* All rights reserved.
*
*/

import java.util.HashMap;
import java.util.List;

import com.pcbly.web.persistence.crm.ClientsDao;
import com.pcbly.web.persistence.table.ColumnDao;
import com.pcbly.web.bean.crm.ClientsBean;
import com.pcbly.web.bean.table.ColumnBean;
import com.pcbly.web.business.BaseServiceImp;
import com.pcbly.web.components.hibernate.support.Page;
import com.pcbly.web.components.form.AbstractAnalyseCommonDataExt;
import com.pcbly.web.components.form.AnalyseCommonDataExtCreate;
import com.pcbly.web.components.form.AnalyseCommonDataExtEdit;
import com.pcbly.web.components.form.AnalyseCommonDataExtView;

 
public class ClientsServiceImp extends BaseServiceImp<ClientsBean> implements ClientsService {
	 public ClientsServiceImp() {
		super();
		// TODO Auto-generated constructor stub
	}
	private ClientsDao clientsDao;
	
	private ColumnDao columnDao;

	public void setColumnDao(ColumnDao columnDao) {
		this.columnDao = columnDao;
	}
	
	public void setClientsDao(ClientsDao clientsDao) {
		this.clientsDao = clientsDao;
	}
	
	@Override
	public ClientsBean getClientsBeanById(String id) throws Exception {
		// TODO Auto-generated method stub
		return clientsDao.get(ClientsBean.class,id);
	}
	
	@Override
	public void removeClientsBeanById(String id) throws Exception{
		clientsDao.removeClientsBeanById(id);
	}
	
	@Override
	public void removeClientsBeanByIds(String ids) throws Exception{
		clientsDao.removeClientsBeanByIds(ids);
	}
	
	
	@Override
	public ClientsBean saveClientsBean(ClientsBean crm) throws Exception{
		return clientsDao.saveClientsBean(crm);
	}
	
	@Override
	public ClientsBean updateClientsBean(ClientsBean crm) throws Exception{
		clientsDao.saveObject( crm);
		return crm;
	}
	public Page<ClientsBean>  findClientsBeanByCond(ClientsBean bean,
			Page<ClientsBean> page, String orderByName, boolean asc)
			throws Exception{
		return clientsDao.findClientsBeanByCond(
				bean, page, orderByName, asc);
	}
	
	@Override
	public String findClientsBeanExtCreate(String tableName) throws Exception {
		// TODO Auto-generated method stub
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtCreate();
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findClientsBeanExtEdit(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = clientsDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtEdit();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public String findClientsBeanExtView(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		List<HashMap<String, String>> dataList = clientsDao
				.findCommnonDataBeanExt(tableName, id);
		List<ColumnBean> columnList = columnDao
				.findColumnBeansByTableName(tableName);
		AbstractAnalyseCommonDataExt common = new AnalyseCommonDataExtView();
		common.setDataList(dataList);
		common.setColumnList(columnList);
		return common.execute().toString();
	}

	@Override
	public void saveClientsBeanExt(String sql) throws Exception {
		// TODO Auto-generated method stub
		clientsDao.saveCommnonDataBeanExt(sql);
	}

	@Override
	public boolean getHasClientsBeanExtData(String tableName, String id)
			throws Exception {
		// TODO Auto-generated method stub
		return clientsDao.getHasCommnonDataBeanExt(tableName, id);
	}
}
